-- CALC_INTRUDE_MONSTER_FOOD_BONUS

-- 计算乱入怪食材奖励
-- @param user     玩家对象
return function(user)
    local layer    = DungeonM.currentLayer();
    local allFoods = ItemM.getFoodMaterial();
    local foods    = {};
    local ret      = {};
    local rank;
    local num;
    local amount;

    if layer < 25 then
        rank = 2;
        num  = 4;
    elseif layer < 50 then
        rank = 3;
        num  = 5;
    else
        rank = 4;
        num  = 6;
    end
    for _,id in pairs(allFoods) do
        if ItemM.query(id, "rank") <= rank then
            table.insert(foods, id);
        end
    end

    for i = 1 , num do
        local rand1  = DungeonM.getRandSeed("intrude_monster_food");
        local rand2  = DungeonM.getRandSeed("intrude_monster_food");
        local foodId = foods[(rand1 % #foods) + 1];
        rank = ItemM.query(foodId, "rank");
        if rank == 1 then
            amount = 15 + rand2 % 11;
        elseif rank == 2 then
            amount = 10 + rand2 % 11;
        elseif rank == 3 then
            amount = 5 + rand2 % 11;
        elseif rank == 4 then
            amount = 3 + rand2 % 5;
        else
            amount = 0
        end
        table.insert(ret, {1, foodId, amount})
    end

    return ret;
end
